package com.sgl.controller;

import com.sgl.entity.AcceptPayOrder;
import com.sgl.entity.OrderHistory;
import com.sgl.service.AcceptPayOrderService;
import com.sgl.util.PageBean;
import com.sgl.util.ReturnData;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * crm入金订单管理
 */

@RestController
@RequestMapping("/sgl/preorder")
public class BgAcceptPayOrderController {


    @Autowired
    AcceptPayOrderService service;

    @RequestMapping("findList")
    public ReturnData findList(PageBean<AcceptPayOrder> pageBean,String payOrderid,String status){
        HashMap<String, Object> param = new HashMap<String, Object>();

        if(StringUtils.isNotBlank(payOrderid)) {
            param.put("orderId", payOrderid);
        }
        if(status!=null) {
            param.put("status", status);
        }

        pageBean.setParam(param);
        List<AcceptPayOrder> list = service.findList(pageBean);
        int count = service.countList(pageBean);
        pageBean.setContent(list);
        pageBean.setTotalCount(count);
        return new ReturnData().okBack(pageBean);
    }

    @PostMapping("/add")
    public ReturnData add(AcceptPayOrder order){
        ReturnData rd = new ReturnData();
        int count = service.insertPayOrder(order);
        if(count > 0) {
            return rd.okBack();
        }
        return rd.failBack();
    }

    @PostMapping("/update")
    public ReturnData update(AcceptPayOrder order){
        ReturnData rd = new ReturnData();
            int count = service.update(order);
        if(count > 0) {
            return rd.okBack();
        }
        return rd.failBack();
    }

    @RequestMapping("/delete")
    public ReturnData delete(String ids) {
        ReturnData rd = new ReturnData();
        if(StringUtils.isBlank(ids)) {
            return rd.failBack("请选择要删除的内容");
        }
        int rs =service.delete(Arrays.asList(ids.split(",")));
        if (rs==0){
            return rd.failBack("没有删除任何内容");
        }
        return rd.okBack("共删除"+rs+"条记录");
    }
}
